package antLogic;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Mark the intern
 * Date: 12-Jul-2007
 * Time: 3:14:20 PM
 */
public class StraightPath extends Path {

    long lastMove;

    protected StraightPath(Ant owner)  {
        super(owner);
        lastMove = new Date().getTime();
    }

    protected String getName()  {
        return "Straight Path";
    }

    protected Segment getSegment(long time) {
        int distance = (int)(((double)owner.velocity * ((time - lastMove)) / (double)AntManager.antMgr.numStepsPerUnit)/1000);
        AntManager.antMgr.log(this, "Moving ant #" + owner.getAntId()
                + " distance of " +distance
                + " units(time=" + ((double)(time - lastMove))/1000
                + "s, speed=" + owner.velocity 
                + "steps/second, unit=" + AntManager.antMgr.numStepsPerUnit+"steps)");
        lastMove = time;
        return new Segment(distance, owner.getBearing());
    }

    protected Segment[] getPath(long time) {
        int distance = (int)((double)owner.velocity * ((time - lastMove)) / (double)AntManager.antMgr.numStepsPerUnit);
        lastMove = time;
        return new Segment[]{new Segment(distance, owner.getBearing())};
    }
}
